<?php

namespace App\Containers\AppSection\Moneybox\Tasks;

use App\Containers\AppSection\Moneybox\Data\Repositories\MoneyboxRepository;
use App\Containers\AppSection\Moneybox\Models\Moneybox;
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Parents\Tasks\Task;

class FindMoneyboxByUUIDTask extends Task
{
    protected MoneyboxRepository $repository;

    public function __construct(MoneyboxRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run(string $uuid): Moneybox
    {
        $result = $this->repository->findWhere(['uuid' => $uuid])->first();

        if (!$result) {
            throw new NotFoundException(__('ship::resource.not-found'));
        }

        return $result;
    }
}
